package com.expressao;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.database.Botao;

import com.example.mobilefala.R;

@SuppressLint("NewApi")
public class AdaptadorImagem extends BaseAdapter {

	public static Intent checkIntent;
	private List<Botao> smiles;
	private Context context;
	AssetManager assetManager;
	public static int i;
	public static View vi;
	public static ViewGroup VG;
    private int base= 140;
    private int altura= 140;
    
    
	public AdaptadorImagem(Context context, List<Botao> list,LayoutParams params) {
		this.context = context;
		smiles = list;
	}

	public AdaptadorImagem(Context context, List<Botao> list) {
		this.context = context;
		smiles = list;
	}

	public AdaptadorImagem() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return smiles.size();
	}

	@Override
	public Object getItem(int arg0) {

		return smiles.get(arg0);
	}

	@Override
	public long getItemId(int posicao) {
		return posicao;
	}
	
	public static ViewGroup getVG() {
		return VG;
	}
	
	@Override
	public View getView(int posicao, View arg1, ViewGroup arg2) {
	   
		if(smiles != null){
			Botao expressao = smiles.get(posicao);
			vi=arg1;
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View v = inflater.inflate(com.example.mobilefala.R.layout.expressao_detalhes, null);
			VG = arg2;
			ImageView img = (ImageView) v.findViewById(com.example.mobilefala.R.id.img);
			TextView t = (TextView) v.findViewById(com.example.mobilefala.R.id.Textimg);
			arg2.getFocusables(0);
			try {
				File f2=new File(expressao.getName_arquivo());

			 	Bitmap mImageBitmap = BitmapFactory.decodeResource(img.getResources(), R.drawable.sem_img);
			 	Bitmap iB2 = Bitmap.createScaledBitmap(mImageBitmap,base, altura, true);
			 	img.setImageBitmap(iB2);
			 	t.setText(expressao.getName()); 
			 	
			 	if(!f2.equals(null)){

			 	File f = new File(expressao.getName_arquivo() + ".jpg");
			 	Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
			 	Bitmap iB = Bitmap.createScaledBitmap(b,altura, base, true);
			 	img.setImageBitmap(iB);
			 	t.setText(expressao.getName()); 
			 	}
//				Log.i("hkjhkl", "get Imagem bt null infalndo getView: " + "..//.." + arg2);

			 	Tts.view2 = arg2;
			   } 
				
			    catch (FileNotFoundException e) 
			    {
			        e.printStackTrace();
			    }
			return v;
		}
		return arg2;
	}
	
}


//import android.app.Activity;
//import android.graphics.drawable.AnimationDrawable;
//import android.media.ToneGenerator;
//import android.os.Build.VERSION;
//import android.preference.PreferenceScreen;
//import android.util.Log;
//import android.widget.ImageButton;
//import br.database.Botao;
//
//import java.util.ArrayList;
//import java.util.Iterator;
//import java.util.TooManyListenersException;
//
//public class AdaptadorImagem {
//  private final Activity activity;
//  private final int cycle;
//  private final ArrayList<Botao> listFocusAnswers;
//  private final int speed;
//  private boolean stop = false;
//  Iterator localIterator = this.listFocusAnswers.iterator();
//
//  public AdaptadorImagem(Activity paramActivity,ArrayList<Botao> paramArrayList, int paramInt1, int paramInt2)
//  {
//    this.cycle = paramInt1;
//    this.speed = paramInt2;
//    this.activity = paramActivity;
//    this.listFocusAnswers = paramArrayList;
//    
//    while (localIterator.hasNext())
//    {
//    	Botao localImageButton = (Botao)localIterator.next();
//     
//      
//      Log.d("logs", "Thread colocando foco na resposta");
//      
//      //    AnimationDrawable localAnimationDrawable = getAnimation(AdaptadorImagem.this.activity, AdaptadorImagem.this.speed, AdaptadorImagem.this.cycle);
//          
////          while (true)
////          {
////            localAnimationDrawable.start();
////            return;
////          }
//    }
//  }
//
//  
//        
//  
//
//}
//
///* Location:           C:\Users\elton\Downloads\Desenvolve-final\classes_dex2jar.jar
// * Qualified Name:     br.com.desenvolve.instrument.ScannerRunnable
// * JD-Core Version:    0.6.0
// */
